[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
##############################################################################
###+---------+################################################################
#+-| AVERAGE |-----------------------------------------------------------+####
#| +---------+ The AVERAGE command totals the values of all expressions |####
#| in <Exp-list> for every record in the current or selected |####
#| alias, then divides the result by the number of records |####
#| within the [Scope] and assigns the result to the |####
#| corresponding variable in <Var-list>. |####
#+-----------------------------------------------------------------------+####
##############################################################################
##############################################################################
#+--| Syntax |-------------------------------------------------+##############
#| [!<Alias>] AVERAGE <Exp-list> [Scope][WHILE <L-exp>] |##############
#| [FOR <L-exp>] TO <Var-list> |##############
#+-------------------------------------------------------------+##############
##############################################################################
##############################################################################
###########+---| Description |------------------------------------+###########
###########| The default scope of AVERAGE is ALL. Every variable |###########
###########| defined in <Var-list> must be DBL type and may not |###########
###########| be a field variable. |###########
###########+------------------------------------------------------+###########
##############################################################################
##############################################################################
#########+--| Example 1 |-------------------------------------------+#########
#########| * Average the cost of an airplane part. |#########
#########| |#########
#########| VARDEF |#########
#########| DBL air_prop |#########
#########| DBL high_prop |#########
#########| DBL twin_prop |#########
#########| DBL air_wheel |#########
#########| DBL high_wheel |#########
#########| DBL twin_wheel |#########
#########| ENDDEF |#########
#########| |#########
#########| PROCEDURE force_main |#########
#########| USE "airplane.dbf" ALIAS airplane |#########
#########| AVERAGE airplane->prop TO air_prop |#########
#########| ? "Average is: ", air_prop |#########
#########| CLOSE ALL |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 2 |-------------------------------------------+#########
#########| * Within a program, average the cost of |#########
#########| * several parts for several airplanes. |#########
#########| |#########
#########| OPEN "airplane.dbf" ALIAS airplane |#########
#########| OPEN "highwing.dbf" ALIAS highwing |#########
#########| OPEN "twin.dbf" ALIAS twin |#########
#########| |#########
#########| !airplane AVERAGE airplane->prop, ; |#########
#########| airplane->wheel TO air_prop,air_wheel |#########
#########| |#########
#########| !highwing AVERAGE highwing->prop, ; |#########
#########| highwing->wheel TO high_prop,high_wheel |#########
#########| |#########
#########| !twin AVERAGE twin->prop,twin->wheel TO ; |#########
#########| twin_prop, twin_wheel |#########
#########| |#########
#########| ? "Averages are: ", air_prop, air_wheel, high_prop, ; |#########
#########| high_wheel, twin_prop, twin_wheel |#########
#########| CLOSE ALL |#########
#########| ENDPRO |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 3 |-------------------------------------------+#########
#########| * An alias and a field can be a parameter to a |#########
#########| * function or procedure. In this case, return |#########
#########| * the ratio of two averages. |#########
#########| |#########
#########| FUNCTION DBL ratio |#########
#########| PARAMETERS ALIAS n1, FIELD DBL(5:2) d1; |#########
#########| ALIAS n2, FIELD DBL(5:2) d2 |#########
#########| VARDEF |#########
#########| DBL t1,t2 |#########
#########| ENDDEF |#########
#########| |#########
#########| !n1 AVERAGE d1 TO t1 |#########
#########| !n2 AVERAGE d2 TO t2 |#########
#########| RETURN t1/t2 |#########
#########| ENDPRO |#########
#########+----------------------------------------------------------+#########
##############################################################################
See Also:
COUNT
SUM
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson